#include "function.h"
void load_data(System *sys)
{
	FILE *fp;
	if((fp = fopen("students","rb")) != NULL)
	{
		sys -> student_count = fread(sys -> students,sizeof(StudentInfo),MAX_STUDENTS,fp);
		fclose(fp);
	}
	if((fp = fopen("exams","rb")) != NULL)
	{
		sys -> exam_count = fread(sys -> exams,sizeof(ExamScore),MAX_STUDENTS,fp);
		fclose(fp);
	}
	if((fp = fopen("reexams","rb")) != NULL)
	{
		sys -> reexam_count = fread(sys -> reexams,sizeof(ReexamScore),MAX_STUDENTS,fp);
		fclose(fp);
	}
	if((fp = fopen("admissions","rb")) != NULL)
	{
		sys -> admission_count = fread(sys -> admissions,sizeof(Admission),MAX_STUDENTS,fp);
		fclose(fp);
	}
	if((fp = fopen("majors","rb")) != NULL)
	{
		sys -> major_count = fread(sys -> majors,sizeof(Major),MAX_MAJORS,fp);
		fclose(fp);
	}	
}

void save_data(System *sys)
{
	FILE *fp;
	fp = fopen("students","wb");
	fwrite(sys -> students,sizeof(StudentInfo),sys -> student_count,fp);
	fclose(fp);
	fp = fopen("exams","wb");
	fwrite(sys -> exams,sizeof(ExamScore),sys -> exam_count,fp);
	fclose(fp);
	fp = fopen("reexams","wb");
	fwrite(sys -> reexams,sizeof(ReexamScore),sys -> reexam_count,fp);
	fclose(fp);
	fp = fopen("admissions","wb");
	fwrite(sys -> admissions,sizeof(Admission),sys -> admission_count,fp);
	fclose(fp);
	fp = fopen("majors","wb");
	fwrite(sys -> majors,sizeof(Major),sys -> major_count,fp);
	fclose(fp);
}

